package com.hawthorn.redis.controller;

import com.hawthorn.entity.po.SysDictPO;
import com.hawthorn.redis.service.dict.DictCacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>todo 系统字典缓存</p>
 * @author: andy.ten@tom.com | xukaixing@hotmail.com
 * @created: 2021/12/19 2:25 PM
 * @version v1.0.2
 * @copyright: Copyright (c)  andyten
 */
@Api(tags = {"redis-sysdict"})
@RestController
@RequestMapping("/dict")
@Slf4j
public class DictCacheController
{
  @Autowired
  private DictCacheService dictCacheService;

  /**
   * <p>todo重新加载字典</p>
   * @author: andy.ten@tom.com
   * @date: 2021/12/20 8:36 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->重新初始化字典", notes = "重新初始化字典")
  @ApiImplicitParams({
  })
  @GetMapping(value = "reloadDict")
  public void reloadDict()
  {
    dictCacheService.init();
  }

  /**
   * <p>todo 刷新字典子项</p>
   * @author: andy.ten@tom.com ｜ xukaixing@hotmail.com
   * @date: 2022/7/22 14:30
   * @version: 1.0.1
   */
  @ApiOperation(value = "字典子项-> 刷新", notes = "刷新字典子项")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "sysDictPO", value = "sysDictPO", dataTypeClass = Object.class)
  })
  @PostMapping("syncDictItem")
  public void syncDictItem(@RequestBody SysDictPO sysDictPO)
  {
    dictCacheService.syncDictItem(sysDictPO);
  }

  /**
   * <p>todo 删除字典子项</p>
   * @author: andy.ten@tom.com ｜ xukaixing@hotmail.com
   * @date: 2022/7/22 14:30
   * @version: 1.0.1
   */
  @ApiOperation(value = "字典子项-> 删除", notes = "删除字典子项")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "dicType", value = "字典类型", dataTypeClass = String.class),
      @ApiImplicitParam(name = "dicCode", value = "字典代码", dataTypeClass = String.class)
  })
  @PostMapping("removeDictItem")
  public void removeDictItem(@RequestParam String dicType, @RequestParam String dicCode)
  {
    dictCacheService.removeDictItem(dicType, dicCode);
  }


}
